package com.googlecode.gwtbb.client.shared.util;

import com.googlecode.gwtbb.client.shared.entity.properties.GetId;

import java.util.Comparator;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Jun 28, 2008
 */
public class ById implements Comparator<GetId> {
	private static ById instance = new ById();

	public static boolean equals(GetId o1, GetId o2) {
		if (o1 == null)
			return o2 == null;
		return o2 != null && ObjectUtils0.nullSafeEquals(o1.getId(), o2.getId());
	}

	public static ById instance() {
		return instance;
	}

	public int compare(GetId o1, GetId o2) {
		if (o1 == null)
			return o2 == null ? 0 : 1;
		return o2 == null ? -1 : ObjectUtils0.nullSafeCompareTo(o1.getId(), o2.getId());
	}
}
